"""
施工人员管理
"""
import logging

import pytest
from Config.Base import Base
from playwright.sync_api import Page, expect, Playwright
from Config.config import *
from Config.URL import *
import allure, os
from Config.Base import Base
from Config.Tool import tool


@pytest.mark.业务系统
@pytest.mark.施工管理
#@allure.step(case_data['caseid'])
#@pytest.mark.parametrize('case', case_data)
def test_case(playwright : Playwright) -> None:
    SetupTeardown = Base(playwright)
    SetupTeardown.goto(url)
    SetupTeardown.login(username_admin, password_admin)
    context = SetupTeardown.context
    page = SetupTeardown.page
    allure.step("登录")
    page.goto(url)
    page.get_by_placeholder("请输入用户名").fill(username_admin)
    page.get_by_placeholder("请输入密码").fill(password_admin)
    page.get_by_role("button", name="登 录").click()
    
    allure.step("跳转施工人员管理URL")
    page.goto(url+url_shigongrenyuanguanli)
    page.get_by_role("tree").get_by_text(bd_zhihuigu).click()
    page.get_by_role("button", name=" 新建").click()
    page.locator("form").filter(
        has_text="基础信息所属标段项目法人标段3玉林联合体施工标项目法人标段").get_by_placeholder("请输入姓名").fill(
        "AutoTest-施工人员")
    page.get_by_placeholder("请输入身份证号").fill("430381199005134135")
    page.locator("label").filter(has_text="性别").click()
    page.get_by_role("textbox", name="请输入联系方式").fill("18075855172")
    page.get_by_placeholder("请输入工种").fill("工种1")
    page.locator("form").filter(
        has_text="基础信息所属标段项目法人标段3玉林联合体施工标项目法人标段").get_by_placeholder("请输入所属班组").fill(
        "班组1")
    page.get_by_placeholder("请输入所属单位").fill("所属单位1")
    page.get_by_placeholder("请输入证书名称").fill("证书1")
    page.get_by_placeholder("请输入证书编号").fill("证书编号1")
    page.get_by_placeholder("请选择证书有效期").fill("2024-01-01")
    page.get_by_placeholder("请选择证书有效期").press("Enter")
    page.get_by_placeholder("请选择入场时间").fill("2024-01-01")
    page.get_by_placeholder("请选择入场时间").press("Enter")
    page.get_by_placeholder("请选择出场日期").fill("2024-01-01")
    page.get_by_placeholder("请选择出场日期").press("Enter")
    page.get_by_placeholder("请输入备注").fill("备注1")
    page.get_by_role("button", name="确 定").click()
    expect(page.get_by_role("alert")).to_contain_text("新建成功！")
    page.wait_for_timeout(2000)
    page.get_by_role("textbox", name="请输入姓名").fill("AutoTest-施工人员")
    page.get_by_role("textbox", name="请输入姓名").click()
    page.get_by_role("button", name=" 查询").click()
    page.wait_for_timeout(500)
    page.get_by_role("button", name="编辑").click()
    page.get_by_role("button", name="确 定").click()
    expect(page.get_by_role("alert")).to_contain_text("修改成功！")
    page.wait_for_timeout(2000)
    page.get_by_role("button", name="删除").click()
    page.get_by_role("button", name="确 定").click()
    expect(page.get_by_role("alert")).to_contain_text("删除成功！")
    context.close()
    SetupTeardown.close()


